package com.ServiceImpl.Admin;

import com.Mapper.Admin.UserInfoMapper;
import com.Model.Admin.UserInfo;
import com.Params.UserInfoParams;
import com.Service.Admin.UserInfoService;
import com.ServiceImpl.BaseSevice;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.io.IOException;
import java.util.List;

@Service
public class UserInfoServiceImpl extends BaseSevice<UserInfo> implements UserInfoService {
    @Override
    public UserInfo getUserInfo(String userName, String password) {

        Example example = new Example(UserInfo.class);
        example.createCriteria().andEqualTo("userName", userName).andEqualTo("password", password);
        List<UserInfo> lst = this.selectByExample(example);

        if (lst == null || lst.size() == 0) {
            return null;

        }
        return lst.get(0);
    }

    @Override
    public PageInfo<UserInfo> userLSt(UserInfoParams userParams) throws IOException {
        // InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        try {


            //   SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            //  SqlSession session = sqlSessionFactory.openSession();

         //   PageHelper.startPage(userParams.getPageNum(), userParams.getPageSize());

            List<UserInfo> lists = ((UserInfoMapper)mapper).getAll();
            PageInfo<UserInfo> info = new PageInfo<>(lists);
            return info;
        } catch (Exception e) {
              e.printStackTrace();
        }

        return null;
    }
}
